package com.tangding.log;

import java.util.HashMap;
import java.util.Map;

import com.tangding.common.exception.GException;
import com.tangding.common.tools.ErrorConstants;
import com.tangding.hprose.api.server.command.Response;

/**
 * @description 
 *
 * @author Ranger
 * @version 2017年12月20日_上午10:22:42
 *
 */
public abstract class LogMatcher {
	private static final Map<String, String> cmd2Display = new HashMap<>();
	static {
		cmd2Display.put("loginlog", "登录");
		cmd2Display.put("addaccountlog", "新增受赠帐号");
		cmd2Display.put("addrolelog", "代理新增");
		cmd2Display.put("updaterolelog", "代理更新");
	}
	
	public static boolean containsCmd(String cmd) {
		return cmd2Display.containsKey(cmd.toLowerCase());
	}
	
	public String cmdDisplay(String cmd, Object... args) {
		return cmd2Display.get(cmd.toLowerCase());
	}
	
	public String responseDisplay(Response response) {
		if(response.getCode() == ErrorConstants.SUCC){
			return "操作成功";
		} 
		return ErrorConstants.getDesc(response.getCode());
	}
	
	public String errDisplay(GException response) {
		if(response.getErr() == ErrorConstants.SUCC){
			return "操作成功";
		} 
		return ErrorConstants.getDesc(response.getErr());
	}
}
